﻿@using admin.Model
@{
    ViewData["Title"] = "ManageInformation";
    Layout = "~/Views/Shared/_SmallWinLayout.cshtml";
    var admin = Model as Administrator;
}


<div class="page-container">
    <div  class="form form-horizontal" id="form-member-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>登录ID：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@admin.Id" id="userid" name="userid" readonly="readonly">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>管理员名：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text auth" value="@admin.Name" placeholder="" id="username" name="username">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>手机：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text auth" value="@admin.Phone" placeholder="" id="mobile" name="mobile" min="8" maxlength="11">
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" onclick="saveinfo('/Home/ManageSaveInformation')" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                <button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    function saveinfo(url) {
        var infoList = new Array();
        $('input[name = username]').blur(function () {
            val = this.value;
            if (val.length == 0) {
                //layer.msg('管理员名称不能为空');
                $(this).attr('placeholder', '管理员名称不能为空');
                $(this).data({ 's': '2' });
            }
            else {
                infoList.push($(this).val());
                $(this).data({ 's': '1' });
            }
        });
        $('input[name = mobile]').blur(function () {
            val = this.value;
            if (val.match(/^1[3|4|5|8]\d{9}$/)) {
                infoList.push($(this).val());
                $(this).data({ 's': '1' });
            }
            else {
                //layer.msg('电话格式不正确');
                $(this).attr('placeholder', '电话不能为空');
                $(this).data({ 's': '3' });
            }
        });
        layer.confirm('确认保存？', function (index) {
            infoList.length = 0;
            $('.auth').blur();
            tot = 0;
            $('.auth').each(function () {
                if ($(this).data('s') == 1) {
                    tot += 1;
                }
                if ($(this).data('s') == 2) {
                    tot += 2;
                }
                if ($(this).data('s') == 3) {
                    tot += 3;
                }
            });
            if (tot == 5) {
                layer.msg('电话格式不正确！,管理员名字不能为空！', { icon: 5, time: 2000 });
            }
            else if (tot == 3) {
                layer.msg('管理员名字不能为空！', { icon: 5, time: 2000 });
            }
            else if (tot == 4) {
                //alert(tot);
                layer.msg('电话格式不正确！', { icon: 5, time: 2000 });
            }
            else if(tot == 2){
                $.ajax({
                    type: 'POST',
                    url: url,
                    data: { "infoitem": infoList.toString() },
                    success: function (response) {
                        if (response == "ok") {
                            layer.msg('信息已保存', { icon: 1, time: 3000 });
                            self.setInterval(function () {  // 这个方法是说在延迟两秒后执行大括号里的方法
                                layer_close();      //关闭当前界面，以下都不行。额，不想刷新来着
                                //window.parent.close();
                                //parent.window.close();
                                //window.close();
                                //window.parent.location.reload();   // 这个方法是刷新当前页面
                            }, 2000); //这里2000代表两秒
                            //parent.layer.close();
                        }
                        else if (response=="nochange") {
                            layer.msg('信息没有改变哦', { icon: 1, time: 3000 });
                            self.setInterval(function () {  // 这个方法是说在延迟两秒后执行大括号里的方法
                                layer_close();      //关闭当前界面
                            }, 2000); //这里2000代表两秒
                        }
                        else if (response == "false") {
                            layer.msg('信息保存失败！请稍后再试', { icon: 5, time: 3000 });
                            infoList.length = 0;
                        }
                        else if (response == "nameError") {
                            layer.msg('信息保存失败！名字输入有误', { icon: 5, time: 3000 });
                            infoList.length = 0;
                        }
                        else if(response =="phoneError"){
                            layer.msg('信息保存失败！电话输入有误', { icon: 5, time: 3000 });
                            infoList.length = 0;
                        }
                    },
                    error: function (response) {
                        layer.msg('信息保存失败！请重新编辑', { icon: 5, time: 3000 });
                        infoList.length = 0;
                    }
                });
            }

        });
    }
</script>